<?php

namespace common\models;

use Yii;

/**
 * This is the model class for table "user_auth_rule".
 *
 * @property int $id
 * @property int $pid 用户权限组id
 * @property string $name 规则名称
 * @property string $link 规则链接
 * @property int $sort 排序
 * @property int $status 状态
 *
 * @property UserAuthGroup $p
 */
class UserAuthRule extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'user_auth_rule';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['pid'], 'required'],
            [['pid', 'sort', 'status'], 'integer'],
            [['name', 'link'], 'string', 'max' => 100],
            [['pid'], 'exist', 'skipOnError' => true, 'targetClass' => UserAuthGroup::className(), 'targetAttribute' => ['pid' => 'id']],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'pid' => '用户权限组id',
            'name' => '规则名称',
            'link' => '规则链接',
            'sort' => '排序',
            'status' => '状态',
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getP()
    {
        return $this->hasOne(UserAuthGroup::className(), ['id' => 'pid']);
    }
}
